function getClass(classname,obj){
	obj=obj||document
	//obj===undefined?document:obj
	if (document.getElementsByClassName) {
		 return obj.getElementsByClassName(classname) 
	}
	else{
		 var arr=[]
		 var all=document.getElementsByTagName("*")
		 for (var i = 0; i <all.length; i++) {
		 	if(checkClass(all[i].className,classname)){
		 		arr.push(all[i])
		 	}

		 } return arr
		 	}
	}
function checkClass(classStr,classname){
	     var arr=classStr.split(" ")
	for (var i = 0; i <arr.length; i++) {
		   if (arr[i]==classname) {
               return true
		   }		   
		   	return false		   
	}
}
//获取设置文本内容
//value为真，设置文本
function operateText(obj,value){
	if (value!=undefined) {
      if (obj.innerText) {
      	  obj.innerText=value}
      	 else{
      	  obj.textContent=value
      	 }
  
	}else{
		if (obj.innerText) {
			return obj.innerText
		}
		else(obj.textContent)
			{return obj.textContent}
		
	}
}
//行内样式和外部样式通用的获取方法
function getStyle(obj,shuxing){
	if (window.getComputedStyle) {
		return window.getComputedStyle(obj,null)[shuxing]
	}
	else{
		return obj.currentStyle[shuxing]
	}
}

function $(selecter,range){
	if (typeof(selecter)=="function") {
		window.onload=function(){
			selecter()
		}
	}
	else if(typeof(selecter)=="string"){
	var range=range||document
	// range==undefined?document:range
	selecter=selecter.replace(/^\s*|\s*$/g,"")
    if (selecter.charAt(0)==".") {
      return getClass(selecter.substring(1),range)
    }
    else if (selecter.charAt(0)=="#") {
      return range.getElementById(selecter.substring(1))
    }
    else if(/^[a-zA-Z][a-zA-Z0-9]{0,10}$/.test(selecter))
      return range.getElementsByTagName(selecter)
    else if(/^<[a-zA-Z][a-zA-Z0-9]{0,10}>$/.test(selecter))
      return range.createElement(selecter.slice(1,-1))
}

	}

//闭包实现选项卡
// var position
// for (var i = 0; i < position.length; i++) {
// 	(function(n){
// 		position[n].onmouseover=function(){
// 	   div[n].style.display="block"
// 	}
// 		position[n].onmouseout=function(){
// 	   div[n].style.display="none"
// 	}
// })(i)
// }


//获取指定对象的子元素集合
// type 指定获取元素节点的类型
//type为true获得元素节点,如果是false,获得有意义的文本
//和元素节点
//默认获得元素节点
 function getChilds(obj,type){
 	var arr=[]
 	var get=obj.childNodes
 	   type=type===undefined?true:type
       if (type) {
       	for (var i = 0; i <get.length; i++) {
       		if (get[i].nodeType==1) {
       			arr.push(get[i])
       		}
       	}

       }
       else{
    for (var i = 0; i <get.length; i++) {
     if (get[i].nodeType==1||get[i].nodeType==3
     	&&get[i].nodeValue.replace(/^\s*|\s*$/g,"")) {
       			
              arr.push(get[i])      
       		}
       	}

       } return arr
 }

function getxChild(obj,num,type){
	var childs=getChilds(obj)
	if (num>childs.length||num<1) {
		return false

	}
	return childs[num];
}
function firstChild(obj,type){
return getChilds(obj)[0]
 
}
function lastChild(obj,type){
return getChilds(obj)[getChilds(obj).length-1];
}

//默认获得下一个非文本和注释的节点
function getNext(obj,type){
	type=type==undefined?false:type

	var next=obj.nextSibling
	if (next==null) {
		return false
		}
	if (type==false) {
        while(next.nodeType=="3"||next.nodeType=="8"){
          next=next.nextSibling
           if (next==null) {
             return false
           }          
        }
        return next
	}
    else if(type==true){
    	while(next.nodeType=="3"&&!next.nodeValue.replace(
    			/^\s*|\s*$/g,"")||next.nodeType
    		=="8"){
    		 next=next.nextSibling
    		 if (next==null) {
    		 	return false
    		 }   		
    	}    	 
    	return next
    }
	}


// 默认得到前一个非文本和注释的节点
function getPrevious(obj,type){
	var previous=obj.previousSibling
	type=type==undefined?false:type
	var previous=obj.previousSibling
	if (previous==null) {
		return false
     }
	if (type==false) {
        while(previous.nodeType=="3"||nodeType=="8"){
          previous=previous.previousSibling
           if (previous==null) {
             return false
           }
          
        }
        return previous
	}

    else if(type==true){
    	while(previous.nodeType=="3"&&!previous.nodeValue.replace(
    			/^\s*|\s*$/g,"")||previous.nodeType
    		=="8"){
    		 previous=previous.previousSibling
    		 if (previous==null) {
    		 	return false
    		 }   		
    	}    	 
    	        return previous
    }
	}

// 插入到下一个
   function insertAfter(obj,newobj,type){
     var next=getNext(newobj,type);
     var parent=obj.parentNode;
      if(next){
         parent.insertBefore(obj,next);
       }
       else{
         parent.appendChild(obj);
       }
   }

//插入到前一个
  function insertBefore (obj,newobj){
     var parent=obj.parentNode;
         obj.insertBefore(obj,newobj);
       }
